#!/bin/bash
read -p "请输入用户名（不能为空）: " username
if [ -z "$username" ]; then
    echo "错误：必须输入用户名！" >&2
    exit 1
fi
stty -echo
read -p "请输入密码（默认123456）: " password
stty echo
password=${password:-123456}
if id "$username" &>/dev/null; then
    echo "错误：用户 $username 已存在！" >&2
    exit 2
else
    useradd "$username"
    echo "$password" | passwd --stdin "$username" &>/dev/null
    echo "用户 $username 创建成功，初始密码：$password"
fi